
class Logic{
    constructor(){
        this.obtain()
        this.business = document.querySelector('#business')
    }
    obtain(){
        fetch('http://chst.vip:1234/api/getcoupon')
        .then(body=>body.json())
        .then(res=>{
            this.render(res.result)
            this.business.addEventListener('click',function(e){
                if(e.target.localName=='a'){
                    // console.log(this);
                    let productid = e.target.getAttribute("conid")
                    // console.log(productid);
                    location.href = `./yhjxiangqing.html?productid=${productid}`
                }
            })
        })
    }
    render(data=[]){
        let newData = [...data]
        console.log(newData);
        let page = ''
        newData.forEach(item=>{
            page+=`
            <a conid=${item.couponId} >
                <img src="${item.couponImg}" alt>
                <p>${item.couponTitle}</p>
            </a>
            `
        })
        this.business.innerHTML = page
    }

}
let logic = new Logic()